import Vue from 'vue'
import Router from 'vue-router'
const IndexHome = resolve => require(['@/views/IndexHome/IndexHome'],resolve)
const Agreement = resolve => require(['@/views/agreement'],resolve)
const PersonCenter = resolve => require(['@/views/PersonCenter/index'],resolve)
const PersonData = resolve => require(['@/views/PersonCenter/personData'],resolve)
const MyMessage = resolve => require(['@/views/PersonCenter/myMessage'],resolve)
const SelectClassCenter = resolve => require(['@/views/SelectClassCenter/index'],resolve)
const MyCurriculum = resolve => require(['@/views/myCurriculum/index'],resolve)
const Phonics = resolve => require(['@/views/phonics'],resolve)
const Comment = resolve => require(['@/views/comment'],resolve)
const RefundDetail = resolve => require(['@/views/refundDetail'],resolve)
const OrderDetail = resolve => require(['@/views/orderDetail'],resolve)
const payOrder  = resolve => require(['@/views/payOrder'],resolve)
const myOrder = resolve => require(['@/views/PersonCenter/myOrder'],resolve)
const CourseDetail = resolve => require(['@/views/courseDetail'],resolve)
const CourseIntrduce = resolve => require(['@/views/courseIntrduce'],resolve)
Vue.use(Router)
var router = new Router({
  routes: [
    {
      path: '/',
      name: 'SelectClassCenter',
      component: SelectClassCenter,
      meta: {
        title: '选课中心'
    }
    },
    {
      path: '/IndexHome',
      name: 'IndexHome',
      component:  IndexHome,
      meta:{
        title:'0元学',
        keepAlive:false
      }
    },
    {
      path: '/agreement',
      name: 'agreement',
      component: Agreement,
      meta: {
        title: 'VIPKID课程服务协议'
    }
    },
    {
      path: '/PersonCenter',
      name: 'PersonCenter',
      component: PersonCenter,
      meta: {
        title: '个人中心'
    }
    },
    {
      path: '/PersonData',
      name: 'PersonData',
      component: PersonData,
      meta: {
        title: '个人资料'
    }
    },
    {
      path: '/myMessage',
      name: 'myMessage',
      component: MyMessage,
      meta: {
        title: '我的信息'
    }
    },
  
    {
      path: '/MyCurriculum',
      name: 'MyCurriculum',
      component: MyCurriculum,
      meta: {
        title: '我的课程'
    }
    },
    {
      path: '/myOrder',
      name: 'myOrder',
      component: myOrder,
      meta: {
        title: '我的订单'
    }
    },
    {
      path: '/phonics',
      name: 'phonics',
      component: Phonics,
      meta: {
        title: '自然拼读'
    }
    },
    {
      path: '/CourseDetail',
      name: 'CourseDetail',
      component: CourseDetail,
      meta: {
        title: '课程详情'
    }
    },
    {
      path: '/CourseIntrduce',
      name: 'CourseIntrduce',
      component: CourseIntrduce,
      meta: {
        title: '课程介绍'
    }
    },
   
    {
      path: '/Comment',
      name: 'Comment',
      component: Comment,
      meta: {
        title: '评论'
    }
    },
    {
      path: '/RefundDetail',
      name: 'RefundDetail',
      component: RefundDetail,
      meta: {
        title: '退款详情'
    }
    },
    {
      path: '/OrderDetail',
      name: 'OrderDetail',
      component: OrderDetail,
      meta: {
        title: '订单详情'
    }
    },
    {
      path: '/payOrder',
      name: 'payOrder',
      component: payOrder,
      meta: {
        title: '支付订单'
    }
    }
    
  ]
})
 // 是否登录的拦截
router.beforeEach((to, from, next)=>{
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  router.afterEach((to,from,next) => {
    window.scrollTo(0,0);
  })
  next();
  // var userInfo=getStore('userInfo');
  // // 如果 该用户存在 则到首页
  // if(userInfo && /\S/.test(userInfo)){
  //   if (to.path === '/login'){
  //       next({ path: '/' })
  //     }else{
  //       next();
  //     }
  // }else{
  //   if (whiteList.indexOf(to.path) !== -1) {
  //     next()
  //   } else {
  //     next('/login')
  //   }
  // }
})
export default router